/*     */ package com.iris.egrant.web;
/*     */ 
/*     */ import java.io.UnsupportedEncodingException;
/*     */ import java.util.Enumeration;
/*     */ import java.util.Map;
/*     */ import java.util.StringTokenizer;
/*     */ import java.util.TreeMap;
/*     */ import javax.servlet.ServletRequest;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.springframework.util.Assert;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public abstract class ServletUtils
/*     */ {
/*     */   public static final String EXCEL_TYPE = "application/vnd.ms-excel";
/*     */   public static final String HTML_TYPE = "text/html";
/*     */   public static final String JS_TYPE = "text/javascript";
/*     */   public static final String JSON_TYPE = "application/json";
/*     */   public static final String XML_TYPE = "text/xml";
/*     */   public static final String TEXT_TYPE = "text/plain";
/*     */   public static final String AUTHENTICATION_HEADER = "Authorization";
/*     */   public static final long ONE_YEAR_SECONDS = 31536000L;
/*     */   
/*     */   public static void setExpiresHeader(HttpServletResponse response, long expiresSeconds) {
/*  41 */     response.setDateHeader("Expires", System.currentTimeMillis() + expiresSeconds * 2L);
/*     */     
/*  43 */     response.setHeader("Cache-Control", "max-age=" + (expiresSeconds * 2L));
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static void setDisableCacheHeader(HttpServletResponse response) {
/*  51 */     response.setDateHeader("Expires", 1L);
/*  52 */     response.addHeader("Pragma", "no-cache");
/*     */     
/*  54 */     response.setHeader("Cache-Control", "no-cache, no-store, max-age=0");
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static void setLastModifiedHeader(HttpServletResponse response, long lastModifiedDate) {
/*  61 */     response.setDateHeader("Last-Modified", lastModifiedDate);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static void setEtag(HttpServletResponse response, String etag) {
/*  68 */     response.setHeader("ETag", etag);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response, long lastModified) {
/*  81 */     long ifModifiedSince = request.getDateHeader("If-Modified-Since");
/*  82 */     if (ifModifiedSince != -1L && lastModified < ifModifiedSince + 1000L) {
/*  83 */       response.setStatus(304);
/*  84 */       return false;
/*     */     } 
/*  86 */     return true;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response, String etag) {
/*  98 */     String headerValue = request.getHeader("If-None-Match");
/*  99 */     if (headerValue != null) {
/* 100 */       boolean conditionSatisfied = false;
/* 101 */       if (!"*".equals(headerValue)) {
/* 102 */         StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ",");
/*     */         
/* 104 */         while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) {
/* 105 */           String currentToken = commaTokenizer.nextToken();
/* 106 */           if (currentToken.trim().equals(etag)) {
/* 107 */             conditionSatisfied = true;
/*     */           }
/*     */         } 
/*     */       } else {
/* 111 */         conditionSatisfied = true;
/*     */       } 
/*     */       
/* 114 */       if (conditionSatisfied) {
/* 115 */         response.setStatus(304);
/* 116 */         response.setHeader("ETag", etag);
/* 117 */         return false;
/*     */       } 
/*     */     } 
/* 120 */     return true;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static void setFileDownloadHeader(HttpServletResponse response, String fileName) {
/*     */     try {
/* 132 */       String encodedfileName = new String(fileName.getBytes(), "ISO8859-1");
/* 133 */       response.setHeader("Content-Disposition", "attachment; filename=\"" + encodedfileName + "\"");
/* 134 */     } catch (UnsupportedEncodingException e) {}
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
/* 145 */     Assert.notNull(request, "Request must not be null");
/* 146 */     Enumeration<String> paramNames = request.getParameterNames();
/* 147 */     Map<String, Object> params = new TreeMap<String, Object>();
/* 148 */     if (prefix == null) {
/* 149 */       prefix = "";
/*     */     }
/* 151 */     while (paramNames != null && paramNames.hasMoreElements()) {
/* 152 */       String paramName = paramNames.nextElement();
/* 153 */       if ("".equals(prefix) || paramName.startsWith(prefix)) {
/* 154 */         String unprefixed = paramName.substring(prefix.length());
/* 155 */         String[] values = request.getParameterValues(paramName);
/* 156 */         if (values == null || values.length == 0)
/*     */           continue; 
/* 158 */         if (values.length > 1) {
/* 159 */           params.put(unprefixed, values); continue;
/*     */         } 
/* 161 */         params.put(unprefixed, values[0]);
/*     */       } 
/*     */     } 
/*     */     
/* 165 */     return params;
/*     */   }
/*     */ }


/* Location:              D:\文件kjt\WEB-INF\lib\egrant-core-2.2.20240205.1659.jar!\com\iris\egrant\web\ServletUtils.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       1.1.3
 */